import { BaseWindow } from "../../../../component/window/BaseWindow";
import { PageTool } from "../../../../common/global/PageTool";
import { Language } from "../../../../../extend/language/Language";
import { ApplyListPanel } from "./ApplyListPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class GuildApplyListWindow
    
    export  class GuildApplyListWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 9);
            this.setSize(620, 380);
            titleHeight = 30;
            this.title = Language.getString(57138);
            this.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._applyListPanel = new ApplyListPanel();
            this._applyListPanel.x = 15;
            this._applyListPanel.y = 38;
            this.addChild(this._applyListPanel);
            this._argeeAllBtn = ObjCreate.createGButton(Language.getString(57139), 435, 340, 70, 24, this);
            this._argeeAllBtn.name = "agree";
            this._refuseAllBtn = ObjCreate.createGButton(Language.getString(57140), 515, 340, 70, 24, this);
            this._refuseAllBtn.name = "refuse";
            this._argeeAllBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._refuseAllBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        public updateListData(arg1: Array<any>): void
        {
            this._pageTool.array = arg1;
            this._applyListPanel.pageBar.maxPage = this._pageTool.pagesCount;
            this.onCurPageChangeHandler(null);
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._applyListPanel.pageBar.currentPage;
            this._applyListPanel.updateDataProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildGetPlayerList, Cache.instance.guild.myGuildInfo.guildId));
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._applyListPanel.tileList.dataProvider.length > 0) 
            {
                loc1 = (arg1.target as GButton).name;
                if (loc1 != "agree") 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDealApply, {"toPlayerId": 0, "oper": false}));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDealApply, {"toPlayerId": 0, "oper": true}));
                }
            }
            return;
        }

        /* internal */ /* var */_applyListPanel: ApplyListPanel;

        /* internal */ /* var */_argeeAllBtn: GButton;

        /* internal */ /* var */_refuseAllBtn: GButton;

        /* internal */ /* var */_pageTool: PageTool;
    }
